package com.mall.common.dao.impl;

import com.mall.common.hibernate.Finder;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.mall.common.dao.ArticleDao;
import com.mall.common.domain.content.ArticleDomain;

import java.util.Date;
import java.util.List;

/**
 * Dao实现类 -文章
 */
@Repository
public class ArticleDaoImpl extends BaseDaoImpl<ArticleDomain, Long> implements ArticleDao {

    @Override
    public List<ArticleDomain> findList(Long catId, Date begin, Date end) {
        String hql = "from ArticleDomain bean where bean.category.id in (" +
                "select node.id from ArticleCategoryDomain node, ArticleCategoryDomain parent where " +
                "node.code like concat(parent.code,'%') and parent.id= :categoryId)";
        Finder f = Finder.create(hql);
        f.setParam("categoryId", catId);
        if(begin!=null&& StringUtils.isNotBlank(begin.toString())){
            f.append(" and bean.modifyDate >= :beginDate");
            f.setParam("beginDate",begin);
        }
        if(end!=null&&StringUtils.isNotBlank(end.toString())){
            f.append(" and bean.modifyDate <= :endDate");
            f.setParam("endDate",end);
        }
        List<ArticleDomain> articleList = f.findHQLList();
        return articleList;
    }
}